using System;
using System.Collections.Generic;
using System.Text;



namespace adt.assoc.DictionaryExtentions
{
	public static class DictionaryExtensions
	{
		public static IDictionary<TKey,TVal> Update<TKey,TVal>(this IDictionary<TKey,TVal> dictA, IDictionary<TKey,TVal> dictB)
		{
	        foreach (KeyValuePair<TKey,TVal> pair in dictB)
	        {
	            dictA[pair.Key] = pair.Value;
	        }
			return dictA;
		}
		
	    public static IDictionary<TKey,TVal> Merge<TKey,TVal>(this IDictionary<TKey,TVal> dictA, IDictionary<TKey,TVal> dictB)
	    {
	        IDictionary<TKey,TVal> output = new Dictionary<TKey,TVal>(dictA);
			return output.Update(dictA).Update(dictB);
	    }
		
		public static string Repr<TKey,TVal>(this IDictionary<TKey,TVal> d)
		{
			var b = new StringBuilder();
			b.Append("{");
			bool first = true;
			foreach (var pair in d) {
				if (!first) b.Append(",");
				b.AppendFormat("{0}: {1}", pair.Key, pair.Value);
				first = false;
			}
			b.Append("}");
			return b.ToString();
		}
	}
}
	
